<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$:TestError.php,2010/05/25 17:00:19 
 * 
 **************************************************************************/
 
 
 
/**
 * @file TestError.php
 * @author huqingping(huqingping@)
 * @date 2010/05/25 17:00:19
 * @version 1.0 
 * @brief 
 *  
 **/

final class TestError extends TestCase
{
	private function getData($if,$of)
	{
		$get = array(
			'_if'=>$if,
			'_of'=>$of
		);
		return array('get'=>$get);
	}

	function testNotfound()
	{
		$input = $this->getData('default','json');
		$ret = $this->fetch('/notfound/xx',$input);
		$json = $ret->json();
		$this->assertTrue(!empty($json));
		$this->assertEquals('hapn.u_notfound',$json['err']);
	}

	function testRedirect()
	{
		$site = 'http://www.?w=';
		$len = strlen($site);
		$input = $this->getData('default','default');
		$ret = $this->fetch('/notfound/x',$input);
		$this->assertTrue(strncmp($ret->redirect,$site.'notfound',$len+7) === 0);
		$input['get']['code'] = 'hapn.error';
		$ret = $this->fetch('/HapN/testException',$input);
		$this->assertTrue(strncmp($ret->redirect,$site.'error',$len+5) === 0);
		$ret = $this->fetch('/HapN/testFatal',$input);
		$this->assertTrue(strncmp($ret->redirect,$site.'fatal',$len+5) === 0);

		$input['get']['code'] = 'hapn.myerr';
		$ret = $this->fetch('/HapN/testException',$input);
		$this->assertTrue(strncmp($ret->redirect,$site.'error',$len+5) === 0);
	}

	function testFatal()
	{
		$input = $this->getData('default','json');
		$ret = $this->fetch('/HapN/testFatal',$input);
		$json = $ret->json();
		$this->assertEquals('hapn.fatal',$json['err']);
	}

	function testException()
	{
		$input = $this->getData('default','json');
		$input['get']['code'] = 'myerr';
		$ret = $this->fetch('/HapN/testException',$input);
		$json = $ret->json();
		$this->assertEquals('myerr',$json['err']);

		$input['get']['code'] = 'myerr2';
		$ret = $this->fetch('/HapN/testException',$input);
		$json = $ret->json();
		$this->assertEquals('myerr2',$json['err']);
	}

}






/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */
?>
